var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var today = date.getDate(); 



// pages/detect/detect.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Show: "none",
    date: year + "-" +month + "-"+ today,
    time: '12:01',
    hindex: 0,
    Harray: [],
    Lindex: 0,
    Larray: [],
    listPfirst:false,
    listSfirst:false,
    listAfirst:false
  },
  showMore:function(){
    let that = this
    that.setData({
      listPfirst: !that.data.listPfirst
    })
  },
  showMoreS: function () {
    let that = this
    that.setData({
      listSfirst: !that.data.listSfirst
    })
  },
  showMoreA: function () {
    let that = this
    that.setData({
      listAfirst: !that.data.listAfirst
    })
  },

  // 防止触摸 
  stop: function () {
    return false
  },
  onLoad: function(options) {




    this.archives();
  },
  // 日期选择
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  // 时间选择
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },

  // 高压原则器
  bindPickerHeigh: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      hindex: e.detail.value
    })
  },
  //  低压原则器
  bindPickerLow: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      Lindex: e.detail.value
    })
  },

  //  建立档案请求接口
  archives: function() {
    var that = this;
    var url = app.util.url('entry/wxapp/signsindex')
    console.log(wx.getStorageSync('userInfo'))
    
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        uid: wx.getStorageSync('userInfo')
      },
      success: function(res) {
        var list = res.data.data
        that.setData({
          List: list,
          bloodPressure: list.highlow.data,
          BloodSugar:list.blood.data,
          UricAcid: list.acid.data
        })
        console.log("体征检测=========>", res);
      }
    })
  },

  // 血压 添加
  btnxy: function(t) {
    var _that = this
    var hide = ""
    var Harrays = _that.data.Harray //获取高压数组值
    var Larrays = _that.data.Larray //获取低压数组值
    for (var i = 90; i <= 130; i++) {
      Harrays.push(i)
    }
    for (var i = 60; i <= 90; i++) {
      Larrays.push(i)
    }
    _that.data.Show == "none" ?
      hide = "block" : hide = ""
    _that.setData({
      Larray: Larrays,
      Harray: Harrays,
      Show: hide,
      xShow: _that.data.List.highlow.type
    })
    console.log("血压", t)
  },

  // 血糖 添加
  btnxt: function(t) {
    var _that = this
    var hide = ""
    _that.data.Show == "none" ?
      hide = "block" : hide = ""
    _that.setData({
      Show: hide,
      xShow: _that.data.List.blood.type
    })
    console.log("血糖", )
  },

  // 获取用户输入血糖的值
  xtext: function(options) {
    var _that = this
    if (options.detail.value < 0) {
      wx.showModal({
        title: '提示',
        content: '您的数值填写有误，请重新填写',
        showCancel: true,
        complete: function (res) {
          _that.setData({
            xtext: 0
          })
        },
      })
      return
    }
    _that.setData({
      xtext: options.detail.value
    })
    console.log(options.detail.value)
  },

  // 尿酸 添加
  btnns: function() {
    var _that = this
    var hide = ""
    _that.data.Show == "none" ?
      hide = "block" : hide = ""
    _that.setData({
      Show: hide,
      xShow: _that.data.List.acid.type
    })
    console.log("尿酸", _that.data.Show)
  },

  // 获取尿酸输入血糖的值
  nsext: function(options) {
    var _that = this
    if (options.detail.value<0){
      wx.showModal({
        title: '提示',
        content: '您的数值填写有误，请重新填写',
        showCancel: true,
        
        fail: function (res) { },
        complete: function (res) { 
          _that.setData({
            nsext: 0
          })
        },
      })

      _that.setData({
        nsext: 0
      })
      return
    }
    _that.setData({
      nsext: options.detail.value
    })
    console.log(options.detail.value)
  },

  // 取消
  close: function() {
    var _that = this
    var hide = ""
    _that.data.Show == "block" ?
      hide = "none" : hide = "none"
    _that.setData({
      Show: hide
    })
  },

  // 确认
  // btnSubmit: function(){
  //   var _that = this
  //   var hide = ""
  //   _that.data.Show == "block" ?
  //     hide = "none" : hide = "none"
  //   _that.setData({
  //     Show: hide
  //   })
  // },

  // 血压确认
  btnSubmitxy: function(t) {
    var _that = this
    var hide = ""
    var Harray = _that.data.Harray[_that.data.hindex] //获取高压的值
    var Larray = _that.data.Larray[_that.data.Lindex] //获取低压的值
    var url = app.util.url('entry/wxapp/signs')
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        op: 'create',
        uid: wx.getStorageSync('userInfo'),
        state: _that.data.List.highlow.type,
        high: Harray,
        low: Larray,
        stime: _that.data.date + ' ' + _that.data.time
      },
      success: function(res) {
        var list = res.data.data
        _that.setData({
          List: list
        })
        console.log("血压添加=========>", res);
        _that.data.Show == "block" ?
          hide = "none" : hide = "none"
        _that.setData({
          Show: hide
        })

        _that.archives()
      }
    })
  },

  // 血糖确认
  btnSubmitxt: function() {
    var _that = this
    var hide = ""
    var url = app.util.url('entry/wxapp/signs')
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        op: 'create',
        uid: wx.getStorageSync('userInfo'),
        state: _that.data.List.blood.type,
        blood: _that.data.xtext,
        stime: _that.data.date + '' + _that.data.time
      },
      success: function(res) {
        var list = res.data.data
        _that.setData({
          List: list
        })
        console.log("血糖=========>", res);
        _that.data.Show == "block" ?
          hide = "none" : hide = "none"
        _that.setData({
          Show: hide
        })

        _that.archives()
      }
    })
  },

  // 尿酸确认
  btnSubmitns: function() {
    var _that = this
    var hide = ""
    var url = app.util.url('entry/wxapp/signs')
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        op: 'create',
        uid: wx.getStorageSync('userInfo'),
        state: _that.data.List.acid.type,
        acid: _that.data.nsext,
        stime: _that.data.date + '' + _that.data.time
      },
      success: function(res) {
        var list = res.data.data
        _that.setData({
          List: list
        })
        console.log("尿酸=========>", res);
        _that.data.Show == "block" ?
          hide = "none" : hide = "none"
        _that.setData({
          Show: hide
        })

        _that.archives()
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})